import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EtchedBorder;
import java.awt.BorderLayout;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.FontMetrics;

class GStatusBar extends JPanel
{
	public static final int STATUS_LOCATION      = 1;
	public static final int STATUS_GRAPHTYPE     = 2;
	public static final int STATUS_ALGORITHM_EXE = 3;
	public static final int STATUS_ALGORITHM_OUT = 4;
	
	private JLabel statusLocation     = new JLabel("Location: ");
	private JLabel statusGraphType    = new JLabel(" ");
	private JLabel statusAlgorithmExe = new JLabel(" ");
	private JLabel statusAlgorithmOut = new JLabel(" ");
	
	public GStatusBar()
	{
		GridBagLayout gridbag = new GridBagLayout();
        GridBagConstraints c = new GridBagConstraints();
        
        setLayout(gridbag);
        
        c.fill = GridBagConstraints.BOTH;
        gridbag.setConstraints(statusLocation,c);
        statusLocation.setPreferredSize(new Dimension(120,20));
        statusLocation.setBorder(new EtchedBorder());
		add(statusLocation);
        
        c.fill = GridBagConstraints.BOTH;
        gridbag.setConstraints(statusGraphType,c);
        statusGraphType.setPreferredSize(new Dimension(120,20));
        statusGraphType.setBorder(new EtchedBorder());
		add(statusGraphType);
        
        c.fill = GridBagConstraints.BOTH;
        gridbag.setConstraints(statusAlgorithmExe,c);
        statusAlgorithmExe.setPreferredSize(new Dimension(80,20));        
		statusAlgorithmExe.setBorder(new EtchedBorder());
		add(statusAlgorithmExe);
		
		c.fill = GridBagConstraints.BOTH;
		c.weightx = 1.0;
        gridbag.setConstraints(statusAlgorithmOut,c);
        statusAlgorithmOut.setPreferredSize(new Dimension(100,20));        
		statusAlgorithmOut.setBorder(new EtchedBorder());
		add(statusAlgorithmOut);
	}
	
	public void setMessage(int i, String text)
	{
		Graphics g = getGraphics();
		FontMetrics fm = g.getFontMetrics();
		
		if(i == STATUS_LOCATION)
		{
			statusLocation.setText("Location: " + text);
			statusLocation.setPreferredSize(new Dimension(Math.max(120, fm.stringWidth("Location: " + text)), 20));
		}
		else if(i == STATUS_GRAPHTYPE)
		{
			statusGraphType.setText(text);
			statusGraphType.setPreferredSize(new Dimension(Math.max(120, fm.stringWidth(text)), 20));
		}
		else if(i == STATUS_ALGORITHM_EXE)
		{
			statusAlgorithmExe.setText(text);
			statusAlgorithmExe.setPreferredSize(new Dimension(Math.max(80, fm.stringWidth(text)), 20));
		}
		else if(i == STATUS_ALGORITHM_OUT)
		{
			statusAlgorithmOut.setText(text);
			statusAlgorithmOut.setPreferredSize(new Dimension(Math.max(100, fm.stringWidth(text)), 20));        
		}
		
		repaint();
	}
	
	public void clear(int i)
	{
		if(i == STATUS_LOCATION)
			statusLocation.setText("Location: " + "");
		else if(i == STATUS_GRAPHTYPE)
			statusGraphType.setText("");
		else if(i == STATUS_ALGORITHM_EXE)
			statusAlgorithmExe.setText("");
		else if(i == STATUS_ALGORITHM_OUT)
			statusAlgorithmOut.setText("");
		
		repaint();
	}
	
	public void clearAll()
	{
		statusLocation.setText("Location: ");
		statusGraphType.setText("");
		statusAlgorithmExe.setText("");
		statusAlgorithmOut.setText("");
		
		repaint();
	}
	
	public String getMessage(int i)
	{
		if (i == STATUS_LOCATION)
			return statusLocation.getText();
		else if (i == STATUS_GRAPHTYPE)
			return statusGraphType.getText();
		else if(i == STATUS_ALGORITHM_EXE)
			return statusAlgorithmExe.getText();
		else if(i == STATUS_ALGORITHM_OUT)
			return statusAlgorithmOut.getText();
			
		return "";
	}
}